package com.llbnk.springcoding.migrate;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
public class MigrateDispatch<T>  {

    @Autowired
    private List<MigrateProcess<T>> migrateProcesses;

    public void migrateAdd(T data,String type){
        for(MigrateProcess migrateProcess:migrateProcesses){
            if(migrateProcess.type().equals(type)){
                migrateProcess.migrateAdd(data);
            }
        }
    }

    public T migrateSelect(String methodName,String type,Object...data){
        for(MigrateProcess migrateProcess:migrateProcesses){
            if(migrateProcess.type().equals(type)){
                return (T) migrateProcess.migrateSelect(methodName,data);
            }
        }
        return null;
    }

}
